package cn.iocoder.yudao.module.train.service.venue;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.train.controller.admin.venue.vo.*;
import cn.iocoder.yudao.module.train.dal.dataobject.venue.VenueDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.train.dal.mysql.venue.VenueMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.train.enums.ErrorCodeConstants.*;

/**
 * 场地 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class VenueServiceImpl implements VenueService {

    @Resource
    private VenueMapper venueMapper;

    @Override
    public Integer createVenue(VenueSaveReqVO createReqVO) {
        // 插入
        VenueDO venue = BeanUtils.toBean(createReqVO, VenueDO.class);
        venueMapper.insert(venue);

        // 返回
        return venue.getId();
    }

    @Override
    public void updateVenue(VenueSaveReqVO updateReqVO) {
        // 校验存在
        validateVenueExists(updateReqVO.getId());
        // 更新
        VenueDO updateObj = BeanUtils.toBean(updateReqVO, VenueDO.class);
        venueMapper.updateById(updateObj);
    }

    @Override
    public void deleteVenue(Integer id) {
        // 校验存在
        validateVenueExists(id);
        // 删除
        venueMapper.deleteById(id);
    }

    @Override
        public void deleteVenueListByIds(List<Integer> ids) {
        // 删除
        venueMapper.deleteByIds(ids);
        }


    private void validateVenueExists(Integer id) {
        if (venueMapper.selectById(id) == null) {
            throw exception(VENUE_NOT_EXISTS);
        }
    }

    @Override
    public VenueDO getVenue(Integer id) {
        return venueMapper.selectById(id);
    }

    @Override
    public PageResult<VenueDO> getVenuePage(VenuePageReqVO pageReqVO) {
        return venueMapper.selectPage(pageReqVO);
    }

    @Override
    public List<VenueDO> getVenueList(VenuePageReqVO pageReqVO) {
        return venueMapper.selectList(pageReqVO);
    }

}
